// pages/join/join.js
import Toast from '@vant/weapp/toast/toast';
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    no: ""
  },
  onJoinClass: function(e) {
    console.log(e)
    let that = this
    console.log(app.globalData.userInfo._id)
    wx.cloud.callFunction({
      name: "joinClass",
      data: {
        no: that.data.no,
        userId: app.globalData.userInfo._id
      }
    }).then(res => {
      console.log(res)

      if (res.result.exist) {
        Toast.success('加入成功');
          wx.navigateTo({
            url: '/pages/student/student',
          })
      } else {
        Toast.success('班级不存在');
      }
    }).catch(res =>{
      console.log(res)
    })
  },
  onInputChange: function (e) {
    console.log(e)
    this.setData({
      no: e.detail
    })
  },
})